package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.UserCheckinDTO;
import com.cskaoyan.wordmemorize.dto.app.UserCheckinStatisticsDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserCheckinCommand;
import com.cskaoyan.wordmemorize.service.UserCheckinService;
import com.cskaoyan.wordmemorize.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/checkin")
public class UserCheckinController {

    @Autowired
    UserCheckinService userCheckinService;

    @PutMapping("card")
    public Result useResignCard() {

        Long userId = StpKit.USER.getLoginIdAsLong();

        userCheckinService.userResignCard(userId);

        return Result.ok();
    }
    // APP端获取用户签到统计信息

    @GetMapping("statistics")
    public Result<UserCheckinStatisticsDTO> getUserCheckinStatistics() {

        Long userId = StpKit.USER.getLoginIdAsLong();

        UserCheckinStatisticsDTO userCheckinStatistics = userCheckinService.getUserCheckinStatistics(userId);

        return Result.ok(userCheckinStatistics);
    }
    // APP端获取用户签到列表

    @GetMapping("list")
    public Result<PageDTO<UserCheckinDTO>> getListUserCheckinStatistics(PageRequest pageRequest) {

        Long userId = StpKit.USER.getLoginIdAsLong();

        PageDTO<UserCheckinDTO> checkInData = userCheckinService.getCheckInData(pageRequest, userId);

        return Result.ok(checkInData);
    }
    // APP端用户签到

    @PostMapping("")
    public Result<UserCheckinStatisticsDTO> userCheckin(@RequestBody UserCheckinCommand userCheckinCommand) {

         Long userId = StpKit.USER.getLoginIdAsLong();

        UserCheckinStatisticsDTO checkin = userCheckinService.checkin(userCheckinCommand, userId);

        return Result.ok(checkin);
    }
}
